<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增评分标准分类')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-type-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">模板名称：</label>
                <div class="col-sm-8">
                    <select  id="gradeTemplate" name="templateId" class="form-control m-b" required>
                        <option value="">请选择模板</option>
                        <option th:each="pets:${templateList}" th:value="${pets.id}"
                                th:text="${pets.templateName}" ></option>
                    </select>

                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">父分类：</label>
                <div class="col-sm-8">
                    <select id="parentType" name="parentId" class="form-control m-b" required>
                        <option value="0">顶级目录</option>
                        <option th:each="pets:${list}" th:value="${pets.typeId}"
                                th:text="${pets.typeName}"></option>
                    </select>

                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">分类名称：</label>
                <div class="col-sm-8">
                    <input name="typeName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">序号：</label>
                <div class="col-sm-8">
                    <input name="typeOrder" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">计分方式：</label>
                <div class="col-sm-8">
                    <select id="scoreModel" name="scoreModel" class="form-control m-b" th:with="type=${@dict.getType('b_score_model')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div id="weightDiv" class="form-group" style="display:none">
                <label class="col-sm-3 control-label">权重(%)：</label>
                <div class="col-sm-8">
                    <input name="weight" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">封顶分数：</label>
                <div class="col-sm-8">
                    <input name="maxScore" class="form-control" type="text"><font color="red">注意：非必填，顶级目录的封顶分数才有效</font>
                </div>
            </div>
<!--            <div class="form-group" >
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <label class="toggle-switch switch-solid">
                        <input type="checkbox" id="status" checked>
                        <span></span>
                    </label>
                </div>
            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-select-css" />
    <th:block th:include="include :: bootstrap-select-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/type"

        var selectedTemplateId = [[${templateId}]];

        $(function() {
            $("select[name='templateId']").val(selectedTemplateId);
        });

        $("#form-type-add").validate({
            focusCleanup: true,
            onkeyup: false,
            rules:{
                weight:{
                    required:false,
                    number:true,
                    min:0,
                    max:100
                }
            }
        });

        $("#gradeTemplate").change(function () {//选择模板 填充分类
			$.ajax({
				url: ctx + "system/type/getTypeByTemplateId",
				type: 'GET',
				data: {
					templateId: $("select[name='templateId']").val()
				},
				success:function (result) {
				    console.log(result);
					$("#parentType").empty();
					$("#parentType").append("<option value='0'>顶级目录</option>");
					for (var i = 0; i < result.data.length; i++){
						$("#parentType").append("<option value=" + result.data[i].typeId + ">" + result.data[i].typeName + "</option>");
					}
				}
			});
		});
        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-type-add').serialize());
            }
        }
        $("#scoreModel").change(function () {
			if($("#scoreModel").val() ==2){
                var weightDiv = document.getElementById("weightDiv");
                weightDiv.style.display = "block";
			}else{
                var weightDiv = document.getElementById("weightDiv");
                weightDiv.style.display = "none";
			}
		});
    </script>
</body>
</html>